/*
 * This code is property of CoreObjects. Use, duplication and disclosure
 * in any form without permission of copyright holder is prohibited.
 *
 */

package com.nen.session;

import java.util.HashMap;
import java.util.Map;

/**
 * Holds information of logged in user sessionIds and related loginUserDetails attributes
 * 
 * @author amitm
 */
public final class SessionMapHolder {
    private static final Map sessionMap = new HashMap();
    
    private SessionMapHolder() {
        
    }

    public static synchronized void addSession(String sessionId, Object loginUserDetails) {
        SessionMapItem item = new SessionMapItem(sessionId, loginUserDetails);
        sessionMap.put(sessionId, item);
    }

    public static SessionMapItem getEntry(String key) {
        return (SessionMapItem)sessionMap.get(key);
    }

    public static boolean isActiveSession(String sessionId) {
        return sessionMap.get(sessionId) != null;
    }

    public static synchronized SessionMapItem invalidateSession(String sessionId) {
        return (SessionMapItem)sessionMap.remove(sessionId);
    }

    public static int size() {
        return sessionMap.size();
    }

    public static synchronized void clear() {
        sessionMap.clear();
    }

}
